<?php
/**
 * Created by PhpStorm.
 * User: BlueIdeaLirui
 * Date: 2020/12/28
 * Time: 14:17
 */

namespace business\company\services;

use business\company\repositories\SelectionSupplierRepository;
use yii\base\InvalidConfigException;

class FhSupplierService
{
    /**
     * 获取供应商各项数据
     * @param $supplierId
     * @throws InvalidConfigException
     */
    public function getSupplierDetail($supplierId){
        $connection = \Yii::$app->get('db');
        // 先获取activity_uid
        $sql = "SELECT
            uid 
        FROM
            `sourcing_meeting`.`sm_activity`
        WHERE
            activity_year = '2022'
            AND `is_deleted` = 0";
        $activityUid =  $connection->createCommand($sql)
            ->queryScalar();
        if ($activityUid){
            $labSql = "SELECT
            is_high_tech,
            is_special_new,
            little_giants,
            enterprise_technology_center 
        FROM
            `sourcing_meeting`.`sm_supplier_mulit_detail` a
            JOIN `sourcing_meeting`.`sm_supplier` b ON b.`uid` = a.`sm_supplier_id` 
        WHERE
            b.`supplier_id` = :supplier_id and a.activity_uid = :activity_uid
            AND a.`is_deleted` = 0";
            $detail =  $connection->createCommand($labSql)
                ->bindValue(':supplier_id', $supplierId)
                ->bindValue(':activity_uid', $activityUid)
                ->queryOne();
        }
        return [
            "is_high_tech" =>  $detail['is_high_tech'] ?? 0,
            "is_special_new" =>  $detail['is_special_new'] ?? 0,
            "little_giants" =>  $detail['little_giants'] ?? 0,
            "enterprise_technology_center" => $detail['enterprise_technology_center'] ?? 0,
        ];
    }
}
